(function() {

	require(['jquery', 'typeahead', __uri('./app.js')], function() {

		$(function() {

			$(document).on('mouseover', '.blocks .one-block .small-img li', function() {//商品列表单个小图切换

				$(this).addClass('active').siblings('li').removeClass('active');
				var src = $(this).children('img').attr('src');
				$(this).parent().siblings('a').children('img.goodsImg').attr('src', src);
			});

			$('.classify .row .item').on('click', function() {//分类只能单个选择
				
				$(this).addClass('active').siblings('.item').removeClass('active');
			});

			require(['typeahead.js'], function() {//小搜索

				$('.options input.search-name').typeahead({
					hint: true,
				  	highlight: true,
				  	minLength: 1
				},
				{
				  	source: function(q, sync) {

				  		return $.ajax({

				  			type: 'POST',
				  			url: '/control/pub/command',
				  			data: {
				  				'command': "com.jackrain.ds.CommSuggestCloudSearchpub",
								'getjson': true,
								'JSON': '{\"query\": \"'+ q +'\",\"hits\": 10}'
				  			},
				  			async: false,
				  			success: function(res) {

				  				var res = JSON.parse(res);
				  				var array = [];
				  				if(res.code == 0)
									if(res.message.suggestions && res.message.suggestions.length != 0)
										$.each(res.message.suggestions, function(i, item) {
											array.push(item.suggestion);
										});
								return sync(array);
				  			}
				  		});
				  	}
				});
			});

			$('.option-price input').on('change', function() {//左侧搜索只能输入数字
				this.value = this.value.replace(/\D/gi,'');
			});
		});
	});
})();